﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Text;

/// <summary>
/// sqlString 的摘要说明
/// </summary>
public class result
{
    public result()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    /// <summary>
    /// 获得数据库连接
    /// </summary>
    public static OleDbConnection getConn()
    {
        string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
        OleDbConnection objConnection;
        strConnection += @"Data Source=D:\working\lie.mdb";
        objConnection = new OleDbConnection(strConnection);
        return objConnection;
    }
    /// <summary>
    /// 获得主页数据
    /// </summary>
    public void fillUp(DataSet ds)
    {
        OleDbDataAdapter oda = new OleDbDataAdapter();
        OleDbCommand olec = new OleDbCommand();
        olec.Connection = getConn();
        try
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select ");
            sql.Append("     ID, ");
            sql.Append("     title, ");
            sql.Append("     group, ");
            sql.Append("     delflag, ");
            sql.Append("     insertuser, ");
            sql.Append("     inserttime ");
            sql.Append("from ");
            sql.Append("     title ");
            sql.Append("where ");
            sql.Append("     title.group = '1' ");
            sql.Append("order by inserttime desc");
            olec.CommandText = sql.ToString();
            oda.SelectCommand = olec;
            oda.Fill(ds);
        }
        catch (Exception ex)
        {
            ex.StackTrace.ToString();
        }
        finally
        {
            oda.Dispose();
            olec.Dispose();
        }
    }
    /// <summary>
    /// 获得主页数据
    /// </summary>
    public void fillDown(DataSet ds, string group)
    {
        OleDbDataAdapter oda = new OleDbDataAdapter();
        OleDbCommand olec = new OleDbCommand();
        olec.Connection = getConn();
        try
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select ");
            sql.Append("     t.ID, ");
            sql.Append("     t.title, ");
            sql.Append("     t.group, ");
            sql.Append("     t.delflag, ");
            sql.Append("     t.insertuser, ");
            sql.Append("     t.inserttime, ");
            sql.Append("     m.mtime ");
            sql.Append("from ");
            sql.Append("     title t ");
            sql.Append(" left join ");
            sql.Append("( ");
            sql.Append(" select t_id,max(m_time) as mtime from message group by t_id ");
            sql.Append(" ) m ");
            sql.Append(" on t.id = m.t_id  ");
            sql.Append("where ");
            sql.Append("  t.group = '");
            sql.Append(group);
            sql.Append(" ' ");
            sql.Append("order by m.mtime desc");
            olec.CommandText = sql.ToString();
            oda.SelectCommand = olec;
            oda.Fill(ds);
        }
        catch (Exception ex)
        {
            ex.StackTrace.ToString();
        }
        finally
        {
            oda.Dispose();
            olec.Dispose();
        }
    }
    /// <summary>
    /// 获得回复数据
    /// </summary>
    public void fillMsg(DataSet ds, string tid)
    {
        OleDbDataAdapter oda = new OleDbDataAdapter();
        OleDbCommand olec = new OleDbCommand();
        olec.Connection = getConn();
        try
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select ");
            sql.Append("     ID, ");
            sql.Append("     t_id, ");
            sql.Append("     m_title, ");
            sql.Append("     m_email, ");
            sql.Append("     m_user, ");
            sql.Append("     m_content, ");
            sql.Append("     m_time ");
            sql.Append("from ");
            sql.Append("     message ");
            sql.Append("where ");
            sql.Append("     t_id = ");
            sql.Append(tid);
            sql.Append(" order by m_time desc ");
            olec.CommandText = sql.ToString();
            oda.SelectCommand = olec;
            oda.Fill(ds);
        }
        catch (Exception ex)
        {
            ex.StackTrace.ToString();
        }
        finally
        {
            oda.Dispose();
            olec.Dispose();
        }
    }
}
